#!/usr/bin/env node

const http = require('http');

http.createServer((req,res)=>{
  if(req.url === '/'){
    let html = '<!DOCTYPE html><html><body>hello world!</body></html>';
    //let buf = Buffer.from('<html><body><h1>hi</h1></body></html>');
    res.writeHead(200,{
    //res.setHeaders('Content-Type','text/html');
    //res.setHeaders('Content-Length',`${buf.length}`);
      'Content-Type':'text/html',
      'Content-Length':Buffer.byteLength(html)
    //res.end(buf);
    });
    res.end(html);
  }else{
    res.statusCode = 404;
    res.setHeader('Content-Type','text/plain');
    res.end('404 Resource not found');
  }
}).listen(8080);
//运行的时候，http://192.168.17.144:8080

